package com.lam.mall.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lam.common.base.domain.BaseEntity;
import com.lam.common.components.dict.annotation.Dict;
import com.lam.common.utils.DateUtil;
import com.lam.common.validate.annotation.DictCheck;
import com.lam.common.validate.annotation.DictValid;
import com.lam.common.validate.group.Add;
import com.lam.mall.common.util.ProductUtil;

/**
 * 商品sku对象 mall_prod_sku
 * 
 * @author admin
 * @date 2023-04-22
 */
@DictCheck
@TableName("mall_prod_sku")
public class ProdSku implements BaseEntity{

    /** 主键 */
    @Null(groups = Add.class, message="id必须为空")
    @TableId(type = IdType.ASSIGN_ID)
    private String id;
    
    /** 商品ID */
    @NotNull(message = "商品ID不能为空")
    private String prodId;

    /** 商品名称 */
    @Size(max = 255, message = "商品名称长度不能超过255个字符")
    private String prodName;

    /** sku名称 */
    @Size(max = 120, message = "sku名称长度不能超过120个字符")
    private String skuName;

    /** 销售属性组合字符串 格式是p1:v1;p2:v2 */
    @Size(max = 2000, message = "销售属性组合字符串 格式是p1:v1;p2:v2长度不能超过2000个字符")
    private String properties;

    /** 原价 */
    private BigDecimal oriPrice;

    /** 价格 */
    private BigDecimal price;

    /** 商品在付款减库存的状态下，该sku上未付款的订单数量 */
    @NotNull(message = "商品在付款减库存的状态下，该sku上未付款的订单数量不能为空")
    private Integer stocks;

    /** 实际库存 */
    private Integer actualStocks;
    /** 实际库存 */
    private Integer soldNum;

    /** 修改时间 */
    @JsonFormat(pattern = DateUtil.PATTERN_DEFAULT)
    @TableField(fill = FieldFill.UPDATE)
    private Date updateTime;

    /** 记录时间 */
    @JsonFormat(pattern = DateUtil.PATTERN_DEFAULT)
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    /** 商家编码 */
    @Size(max = 100, message = "商家编码长度不能超过100个字符")
    private String partyCode;

    /** 商品条形码 */
    @Size(max = 100, message = "商品条形码长度不能超过100个字符")
    private String modelId;

    /** sku图片 */
    @Size(max = 500, message = "sku图片长度不能超过500个字符")
    private String pic;

    /** 版本号 */
    private Integer version;

    /** 商品重量 */
    private Integer weight;

    /** 商品体积 */
    private Integer volume;

    /** 状态, 0-禁用 1-启用 */
    @DictValid(message = "无效的状态, 0-禁用 1-启用")
    @Dict(dictCode = "status_type")
    private Integer status;

    /** 删除状态, 1-正常 0-已删除 */
    @DictValid(message = "无效的删除状态, 1-正常 0-已删除")
    @Dict(dictCode = "del_status")
    private Integer delStatus;
    
    /** sku属性 */
    @TableField(exist = false)
    private List<SkuProperties> propertiesList;
    
    public void convertProperties(boolean reverse) {
    	if(reverse) {
			this.propertiesList = ProductUtil.skuProperties2List(properties);
    		return;
    	}
    	
		properties = ProductUtil.list2SkuProperties(propertiesList);
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    } 

    public void setProdId(String prodId) {
        this.prodId = prodId;
    }

    public String getProdId() {
        return prodId;
    }    
    
    public void setProdName(String prodName) {
        this.prodName = prodName;
    }

    public String getProdName() {
        return prodName;
    }    
    
    public void setSkuName(String skuName) {
        this.skuName = skuName;
    }

    public String getSkuName() {
        return skuName;
    }    
    
    public void setProperties(String properties) {
        this.properties = properties;
    }

    public String getProperties() {
        return properties;
    }    
    
    public void setOriPrice(BigDecimal oriPrice) {
        this.oriPrice = oriPrice;
    }

    public BigDecimal getOriPrice() {
        return oriPrice;
    }    
    
    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getPrice() {
        return price;
    }    
    
    public void setStocks(Integer stocks) {
        this.stocks = stocks;
    }

    public Integer getStocks() {
        return stocks;
    }    
    
    public void setActualStocks(Integer actualStocks) {
        this.actualStocks = actualStocks;
    }

    public Integer getActualStocks() {
        return actualStocks;
    }    
    
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }    
    
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getCreateTime() {
        return createTime;
    }    
    
    public void setPartyCode(String partyCode) {
        this.partyCode = partyCode;
    }

    public String getPartyCode() {
        return partyCode;
    }    
    
    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public String getModelId() {
        return modelId;
    }    
    
    public void setPic(String pic) {
        this.pic = pic;
    }

    public String getPic() {
        return pic;
    }    
    
    public void setVersion(Integer version) {
        this.version = version;
    }

    public Integer getVersion() {
        return version;
    }    
    
    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Integer getWeight() {
        return weight;
    }    
    
    public void setVolume(Integer volume) {
        this.volume = volume;
    }

    public Integer getVolume() {
        return volume;
    }    
    
    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getStatus() {
        return status;
    }    
    
    public void setDelStatus(Integer delStatus) {
        this.delStatus = delStatus;
    }

    public Integer getDelStatus() {
        return delStatus;
    }

	public List<SkuProperties> getPropertiesList() {
		return propertiesList;
	}

	public void setPropertiesList(List<SkuProperties> propertiesList) {
		this.propertiesList = propertiesList;
	}

	public Integer getSoldNum() {
		return soldNum;
	}

	public void setSoldNum(Integer soldNum) {
		this.soldNum = soldNum;
	}


}
